 //
 import { useEffect } from "react"
 import useGetUserInfo from "./useGetUserInfo"
import { useLocation, useNavigate } from "react-router-dom"
import { isLoginOrRegister, isNoNeedUserInfo, LOGIN_PATHNAME, MANAGE_INDEX_PATHNAME } from "../router"
 function useNavPage(waitingUserData:boolean){
    const nav=useNavigate()
    const {pathname}=useLocation()
    const {username}=useGetUserInfo()
    useEffect(()=>{
        if(waitingUserData) return
        //已经登陆了 
        if(username){
            if(isLoginOrRegister(pathname)){    
                nav(MANAGE_INDEX_PATHNAME)
            }
            return 
        }
        //未登录
        if(isNoNeedUserInfo(pathname)){
            return
        }else{
            nav(LOGIN_PATHNAME)
        }   

    },[nav, pathname, username, waitingUserData])
 }
 export default useNavPage